aboutsummaryrefslogtreecommitdiff
path: root/src/routes/player/[player]/+page.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/player/[player]/+page.ts')
-rw-r--r--src/routes/player/[player]/+page.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/routes/player/[player]/+page.ts b/src/routes/player/[player]/+page.ts
new file mode 100644
index 0000000..bd7c002
--- /dev/null
+++ b/src/routes/player/[player]/+page.ts
@@ -0,0 +1,24 @@
+import type { PageLoad } from './$types'
+import { fetchApi } from '$lib/api'
+
+export const load = (async ({ params, fetch }) => {
+ const player: string = params.player!
+
+ const data = await fetchApi(`player/${player}?customization=true`, fetch).then(r => r.json())
+
+ if (!data.player) {
+ return {
+ status: 404,
+ error: 'Unknown player',
+ }
+ }
+
+ if (data.player.username !== player) {
+ return {
+ redirect: `/player/${data.player.username}`,
+ status: 302,
+ } as any
+ }
+
+ return data
+}) satisfies PageLoad